﻿@{
    //Layout = null;
    Layout = "~/Views/Shared/MainLayout.cshtml";
    ViewBag.Title = "分类列表";
}
@model ConvertMediaPro.Models.CategoryViewModel

@*<!DOCTYPE html>

    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        <div>
        </div>
    </body>
    </html>*@

<div class="row">
    <div class="col-md-9"></div>
    <div class="col-md-1">
    </div>
    <div class="col-md-2">
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#AddModel">
            添加微信菜单名称
        </button>
    </div>
</div>
<div class="row">
    <div class="col-md-12">
        <table class="table table-condensed">
            <thead>
                <tr>
                    <th class="col-md-1">微信菜单名称</th>
                    <th class="col-md-2">创建时间</th>
                    <th class="col-md-2">最后修改时间</th>
                    <th class="col-md-3">微信链接地址</th>
                    <th class="col-md-4">操作</th>
                </tr>
            </thead>
            <tbody>
                @{
                    foreach (Model.Category item in Model.CategoryList)
                    {
                        var name= "查看" + item.Name + "列表";
                        var url = Model.WxUrl + "/Read/Content/" + item.Id;
                        <tr class="active">
                            <th class="col-md-1">@item.Name</th>
                            <td class="col-md-2">@item.CreateTime</td>
                            <td class="col-md-2">@item.LastUpdateTime</td>
                            <td class="col-md-3">@url</td>
                            <td class="col-md-4">
                                <a href="/Read/ContentList?Id=@item.Id">@name</a>|
                                @*<a href="/Category/Update?Id=@item.Id">修改</a>|*@
                                @Ajax.ActionLink("修改", "ModifyInit", "Category", new { id = item.Id }, new AjaxOptions()
                                    {
                                        OnSuccess = "modifyInitAfter",
                                        HttpMethod="Get"
                                    }, new {
                                        //data_toggle = "modal",
                                        //data_target = "#modifyModel"
                                    }) |
                                @Ajax.ActionLink("删除", "Delete", "Category", new { id = item.Id }, new AjaxOptions()
                                    {
                                        Confirm = "确定删除？",
                                        OnSuccess = "deleteAfter"
                                    }, new { })
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
    </div>
</div>
@*添加*@
<!-- Modal -->
<div class="modal fade" id="AddModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        @{
            using (Html.BeginForm("Add", "Category", FormMethod.Post))
            {
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">添加</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-2">名称</div>
                            <div class="col-md-6">@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })</div>
                            <div class="col-md-4">@Html.ValidationMessageFor(m=>m.Name)</div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </div>
            }
        }
    </div>
</div>
@*修改*@
<!-- Modal -->
<div class="modal fade" id="modifyModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
    <div class="modal-dialog" role="document">
        @{
            using (Html.BeginForm("Modify", "Category", FormMethod.Post))
            {
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">修改</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-2">名称</div>
                            <div class="col-md-6">
                                @Html.TextBoxFor(m => m.Name, new { @class = "form-control", id = "modifyName" })
                                @*<input type="text" name="Name" id="modifyName" value="" />*@
                            </div>
                            <div class="col-md-4">
                                @Html.ValidationMessageFor(m => m.Name)
                            <input type="hidden" name="id" id="cateId" value="" />
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </div>
            }
        }
    </div>
</div>

<script type="text/javascript">
    function modifyInitAfter(data){
        if (data) {
            $('#modifyName').val(data.cateName);
            //jQuery('#modifyName').val(data.cateName);
            $('#cateId').val(data.cateId);
            $('#modifyModel').modal('show')
        }
    }
    function deleteAfter(data) {
        if (data==true) {
            window.location.href = "/Category/Index";
        }
    }
</script>